<template>
	<view class="container bg-w">
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="项目监管">
				<template slot='left'>
					<view class="flex width-100">
						<i class='iconfont iconfanhui' @click='goHome()'></i>
					</view>
				</template>
			</uni-nav-bar>
		</view>
		<view class="position-r-top">
			<uni-segmented-control :current="current" :values="segmentedAll" @clickItem="onClickItem" style-type="text" active-color="#09AAE9"></uni-segmented-control>
			<view class="content">
					<view v-if="current === 0">
							<ProjectInformation :BasicInfo='BasicInfo' :waterName="waterName" :entityTypeAll='entityTypeAll'></ProjectInformation>
					</view>
					<view v-if="current === 1">
							<InformationDocument :projectId = 'projectId'></InformationDocument>
					</view>
					<view v-if="current === 2">
							<SubitemManagement :subprojectData='subprojectData' @subprojectMethod='subprojectMethod'></SubitemManagement>
					</view>
					<view v-if="current === 3">
							<InvestmentManagement :projectId="projectId"></InvestmentManagement>
					</view>
			</view>
		</view>
	</view>
</template>

<script>
	import ProjectInformation from '@/pages/supervise/ProjectInformation/ProjectInformation'
	import InformationDocument from '@/pages/supervise/InformationDocument/InformationDocument'
	import SubitemManagement from '@/pages/supervise/SubitemManagement/SubitemManagement'
	import InvestmentManagement from '@/pages/supervise/InvestmentManagement/InvestmentManagement'
	import {
		projectInfo,
		entityType,
		subproject,
		zdhjcsubassessment,
		waterManagement
	} from '@/common/api/api.js'
	export default {
		components: {ProjectInformation,InformationDocument,SubitemManagement,InvestmentManagement},
		data() {
			return {
				projectId:null,
				current:0,
				segmentedAll:['项目信息','资料文件','子项管理','投资管理'],
				// segmentedAll:['项目信息','资料文件','子项管理',],
				BasicInfo: {},//基础信息
				entityTypeAll: [],
				subprojectParameter:{
					subProjectName: null,
					districtCode: null,
					type: null,
					status: null,
					projectId:null,
					pageNo: 1,
					pageSize: 10
				},
				totalPage:null,
				subprojectData:[],
				waterName: ""
			}
		},
			onLoad(option) {
				this.projectId = option.projectId
				this.subprojectParameter.projectId = option.projectId
				entityType().then(res => {
					this.entityTypeAll = res.data
				})
				projectInfo(option.projectId).then(res => {
					if (res.data) {
						this.BasicInfo = res.data
						// zdhjcsubassessment(this.BasicInfo.assessmentId).then(resId => {
						// 	if(resId.data){
						// 		this.$set(this.BasicInfo,'zdhjcsubassessmentName',resId.data)
						// 	}else{
						// 			this.$set(this.BasicInfo,'zdhjcsubassessmentName','')
						// 	}
						// })
						if(this.BasicInfo.assessmentId){
							zdhjcsubassessment(this.page).then(res => {
								if(res.data.records){
									res.data.records.forEach(obj => {
										if(obj.assessmentId == this.BasicInfo.assessmentId){
											this.$set(this.BasicInfo,'zdhjcsubassessmentName',obj.assessmentName)
										}
									})
								}
							})
						}
						this.BasicInfo.participates.forEach(obj => {
							this.entityTypeAll.forEach(obj2 => {
								if (obj.type == obj2.id) {
									this.$set(obj, 'typeName', obj2.label)
								}
							})
						})
						waterManagement(res.data.waterId).then(res=> {
							if(res.code == 20000) this.waterName = res.data.name;
						})
					}
				})
				this.subprojectMethod();
			},
		methods:{
			goHome(){
				uni.navigateTo({
					url:'/pages/index/index'
				})
			},
			onClickItem(e) {
					if (this.current !== e.currentIndex) {
							this.current = e.currentIndex;
					}
			},
			subprojectMethod(value){
				this.subprojectData = []
				if(value){
					this.subprojectParameter.subProjectName = value.subProjectName
					this.subprojectParameter.pageNo = value.pageNo
				}
				subproject(this.subprojectParameter).then(res =>{
					this.totalPage = res.data.pages
					this.subprojectData = this.subprojectData.concat(res.data.records)
				})
			},
			onReachBottom() { //上拉加载更多
				this.subprojectParameter.pageNo++
				if (this.subprojectParameter.pageNo <= this.totalPage) {
					this.subprojectMethod();
				}
			},
			
		}
	}
</script>

<style scoped>
</style>
